![]() |
PATH![]() |
![]() ![]() |
If a parameter doesn't belong to the right class, it may be possible to coerce it, that is, to change it into a value of another class. For example, you can coerce an integer such as 2 to the corresponding string "2" using the As operator:
2 as string
--result: "2"
AppleScript performs some coercions, including the previous one, automatically. For example, the following statement uses the Copy command to set the name of a folder.
tell application "Finder"
copy 12 to name of folder 1 of disk "RAM disk"
end tell
Because a folder name is a string, the direct parameter of the Copy command should also be a string. When AppleScript executes this script, it automatically coerces the integer 12 to the string "12" and uses that string to set the name of the first folder.
The coercions that AppleScript can perform are listed in Values and Constants. Applications can also perform additional coercions, such as coercions for classes that are specific to an application. These coercions are listed in the documentation for the application. Scripting additions, which are described in Scripting Addition Commands, can also perform coercions.